<template>
	<view>
		<merchants v-if="PageCur=='merchants' && token" :key="commponent1Key" ref="merchants"></merchants>
		<about v-if="PageCur=='about' && !token" :key="commponent5Key" ref="about"></about>
		<people v-if="PageCur=='people'" :key="commponent2Key" ref="people"></people>
		<oil v-if="PageCur=='oil'" :key="commponent3Key" ref="oil"></oil>
		<record v-if="PageCur=='record'" :key="commponent4Key" ref="record"></record>
		<gas v-if="PageCur=='gas' && merchant.orgCode == 'A05'" :key="commponent5Key" ref="gas"></gas>
		<sign v-if="PageCur=='sign' && merchant.orgCode == 'A25'" :key="commponent6Key" ref="sign"></sign>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view v-if="token" :class="PageCur=='merchants'?'action text-green':'action text-gray'" @click="NavChange" data-cur="merchants">
				<view class='cuIcon-homefill'></view>主页
			</view>
			<view v-if="!token" :class="PageCur=='about'?'action text-green':'action text-gray'" @click="NavChange" data-cur="about">
				<view class='cuIcon-phone'></view>联系我们
			</view>
			<view v-if="merchant.orgCode != 'A25'" :class="PageCur=='record'?'action text-green':'action text-gray'" @click="NavChange" data-cur="record">
				<view class='cuIcon-news'></view>台账
			</view>
			<view v-if="merchant.orgCode != 'A25'" :class="PageCur=='oil'?'action text-green':'action text-gray'" @click="NavChange" data-cur="oil">
				<view class='cuIcon-circlefill'></view>隔油池
			</view>
			<view v-if="merchant.orgCode == 'A05'" :class="PageCur=='gas'?'action text-green':'action text-gray'" @click="NavChange" data-cur="gas">
				<view class='cuIcon-hotfill'></view>油烟
			</view>
			<view v-if="merchant.orgCode == 'A25'" :class="PageCur=='sign'?'action text-green':'action text-gray'" @click="NavChange" data-cur="sign">
				<view class='cuIcon-news'></view>签到
			</view>
			<view :class="PageCur=='people'?'action text-green':'action text-gray'" @click="NavChange" data-cur="people">
				<view class='cuIcon-people'></view>商户
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		computed: {
			...mapState([
				'merchant',
				'token',
				'scene'
			])
		},
		data() {
			return {
				PageCur: 'people',
				commponent1Key: 0,
				commponent2Key: 0,
				commponent3Key: 0,
				commponent4Key: 0,
				commponent5Key: 0,
				commponent6Key: 0
			}
		},
		onLoad:function(){
			this.PageCur = 'people'
			++this.commponent1Key
			++this.commponent2Key
			++this.commponent3Key
			++this.commponent4Key
			++this.commponent5Key
			++this.commponent6Key
		},
		onShow(options){
			let entryDetail = uni.getStorageSync('entryDetail')
			if(this.PageCur == 'record' && entryDetail == 'recordDetail'){
				//如果是从台账详情页面编辑完过来
				this.$refs['record'].downCallback();
			}
			else if(this.PageCur == 'oil' && entryDetail == 'oilDetail'){
				//如果是从隔油池详情页面编辑完过来
				this.$refs['oil'].downCallback();
			}
			else if(this.PageCur == 'gas' && entryDetail == 'gasDetail'){
				//如果是从烟气详情页面编辑完过来
				this.$refs['gas'].downCallback();
			}
			else if(this.PageCur == 'sign' && entryDetail == 'signDetail'){
				//如果是从烟气详情页面编辑完过来
				this.$refs['sign'].downCallback();
			}
			else if(this.PageCur == 'people' && entryDetail == 'peopleDetail'){
				//如果是从商户详情页面编辑完过来
				this.$refs['people'].getMerchantDetail();
			}
			else if(this.PageCur == 'merchants' && entryDetail == 'merchantDetail'){
				//如果是从商户详情页面编辑完过来
				this.$refs['merchants'].onRefresh();
			}
			uni.removeStorageSync('entryDetail');
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			}
		},
		mounted(){
			if(!this.token){
				let enterOptions = uni.getEnterOptionsSync()
				if(enterOptions && enterOptions.query && enterOptions.query.scene){
					this.$store.dispatch('setScene', {
						scene: enterOptions.query.scene
					});
				}
			}
				
			if(this.scene){
				console.log('扫描商户进的小程序')
				//有场景值，说明是扫描商户进的小程序，切换到商户tab页面，获取商户信息
				this.PageCur = 'people'
			}
			else{
				console.log('没有场景值')
				//没有场景值，正常进入
				//没有token有没有场景值，跳转到登录页面
				if(!this.token){
					console.log('没有登录过')
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
				else{
					console.log('有登录过')
					//有token，为登录用户，切换到商户列表页面
					this.PageCur = 'people'
				}
			}
		}
	}
</script>

<style>

</style>
